export {}
// 1.对象的定义和重点提示
let objv1: {} = {
  name: '张三',
  address: '北京',
}
console.log(objv1)

let objv2: { name: string; address: string; sayHello2: () => void } = {
  name: '张三2',
  address: '北京2',
  sayHello2() {
    console.log('hello')
  },
}
console.log(objv2)

type objv3 = {
  name: string
  address: string
  sayHello3: () => void
}
let objv31: objv3 = {
  name: '张三3',
  address: '北京3',
  sayHello3() {
    console.log('hello')
  },
}
console.log(objv31)

console.log()
console.log('=======================================================1')
// 2.接口的定义和重点提示
interface Interv21 {
  blog: string
  name: string
  sayHello1?: () => void
}

interface Interv22 {
  edt: boolean
}

class Clazzv1 implements Interv21, Interv22 {
  blog: string
  name: string
  edt: boolean
  constructor(blog: string, name: string, edt: boolean) {
    this.blog = blog
    this.name = name
    this.edt = edt
  }
  sayHello1() {
    console.log('hello')
  }
}

const clazzv21 = new Clazzv1('faithBlog', '张三', true)
console.log(clazzv21)

console.log()
console.log('=======================================================2')
// 3.更多关于接口的内容
// 接口描述函数
interface Interv23 {
  (num1: number, num2: number): number
}

const interv23: Interv23 = (a, b) => a + b
console.log(interv23(1, 2))

type TupleV24 = [string, number, boolean]
const tuplev24: TupleV24 = ['faithBlog', 1, true]

interface TupleV25 {
  tuplef: [string, number, boolean]
}

const tuplev25: TupleV25 = {
  tuplef: ['faithBlog', 1, true],
}

// 接口继承
interface Bank26 {
  CNY: number
}
interface Bank27 {
  CNY: number
  USD: number
}

interface Bank28 extends Bank26, Bank27 {
  SGD?: number
  [Currency: string]: number | undefined
  // 只读字段
  readonly BandId: number
}

const bankv28: Bank28 = {
  CNY: 100,
  USD: 200,
  EUR: 10000,
  BandId: 12345,
}
console.log(bankv28)
console.log()
console.log('=======================================================3')
// 4.最后总结
console.log()
console.log('=======================================================4')
// 5.声明合并
interface Bank29 {
  name: string
  address: string
}

interface Bank29 {
  name: string
  age: number
}

const bankv29: Bank29 = {
  name: 'faithBlog',
  address: '北京',
  age: 18,
}
console.log(bankv29)

// type不支持合并
type Bankv30 = {
  name: string
}

// 重复会报错
// type Bankv30 = {
//     age: number
// }
type Bankv31 = {
  name: string
  age: number
}

type Bankv32 = Bankv30 & Bankv31
const bankv32: Bankv32 = {
  name: 'faithBlog32',
  age: 18,
}
console.log(bankv32)

type Bankv33 = Bankv30 | Bankv31
const bankv33: Bankv33 = {
  name: 'faithBlog33',
}
console.log(bankv33)
